package com.godz.controller.index2;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index2HpMapper;
import com.godz.mapper.index2ItemMapper;
import com.godz.mapper.index2SecretMapper;
import com.godz.pojo.index2Hp;
import com.godz.pojo.index2Item;
import com.godz.pojo.index2Secret;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class index2Controller {
    final
    index2HpMapper hpMapper;//我的荣誉
    final
    index2ItemMapper itemMapper;//项目经验
    final
    index2SecretMapper secretMapper;//我的秘密

    public index2Controller(
            index2HpMapper hpMapper,
            index2ItemMapper itemMapper,
            index2SecretMapper secretMapper
    ) {
        this.hpMapper = hpMapper;
        this.itemMapper = itemMapper;
        this.secretMapper = secretMapper;
    }

    @RequestMapping("/index2")
    public String index2(Model model){
        List<index2Hp> index2HpList = hpMapper.queryAllHp();
        //由于网页中写的htmlJs分类名,后台肯定是没有的,单独判断赋js变量名
        for (com.godz.pojo.index2Hp index2Hp : index2HpList) {
            if(index2Hp.getHpCategory()==1){
                index2Hp.setCname("filter-Tech");
            }else if(index2Hp.getHpCategory()==2){
                index2Hp.setCname("filter-Lite");
            }else{
                index2Hp.setCname("filter-Phys");
            }
        }
        model.addAttribute("HpList",index2HpList);
        //项目
        QueryWrapper<index2Item> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("item_date").last("limit 4");
        List<index2Item> items = itemMapper.selectList(wrapper);
        model.addAttribute("items",items);
        //秘密
        List<index2Secret> secretList = secretMapper.queryAllSecret();
        model.addAttribute("secretList",secretList);
        return "index2";
    }
}
